﻿using System.Web.Mvc;
using Api.Common;
using AppManager.IBLL;

namespace AppManager.Web.Controllers
{
    public class HomeController : Controller
    {
        IAppService appService;
        IAppInfoService appInfoService;
        public HomeController(IAppService appServ, IAppInfoService appInfoServ)
        {
            appService = appServ;
            appInfoService = appInfoServ;
        }
        public ActionResult Index(int? id)
        {
            if (id == null)
            {
                return PartialView("_404");
            }
            var app = appService.GetModel(s => s.Id == id.Value);

            if (app == null) return PartialView("_404");

            var list = appInfoService.GetListNoTrack(s => s.AppId == app.Id);
            app.AppInfos = list;

            return View(app);
        }

        public void QrCode(string url)
        {
            QrCodeHelper.Create(url);
        }

        public ActionResult Scan(int? id)
        {
            if (id == null)
            {
                return PartialView("_404");
            }
            var app = appService.GetModel(s => s.Id == id.Value);

            if (app == null) return PartialView("_404");

            var list = appInfoService.GetListNoTrack(s => s.AppId == app.Id);
            app.AppInfos = list;

            return View(app);
        }

        public ActionResult Test(int? id)
        {
            if (id == null)
            {
                return PartialView("_404");
            }
            var app = appService.GetModel(s => s.Id == id.Value);

            if (app == null) return PartialView("_404");

            var list = appInfoService.GetListNoTrack(s => s.AppId == app.Id);
            app.AppInfos = list;

            return View(app);
        }

        public ActionResult T(int? id)
        {
            if (id == null)
            {
                return PartialView("_404");
            }
            var app = appService.GetModel(s => s.Id == id.Value);

            if (app == null) return PartialView("_404");

            var list = appInfoService.GetListNoTrack(s => s.AppId == app.Id);
            app.AppInfos = list;

            return View(app);
        }
    }
}